//
//  GetCommentsViewController.m
//  DeliciousFood1
//
//  Created by brother on 15/10/22.
//  Copyright © 2015年 com.hxm. All rights reserved.
//

#import "GetCommentsViewController.h"
#import <AFNetworking.h>
#import "AppDelegate.h"
#import "User.h"

@interface GetCommentsViewController ()
@property (weak, nonatomic) IBOutlet UITextView *textView;

@end

@implementation GetCommentsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (IBAction)sendComments:(id)sender {
    //添加评论
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    NSString *url = @"http://localhost:8888/thinkphp/index.php/home/food/addComments";
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"foodid"] = [NSNumber numberWithInt:self.foodid];
    AppDelegate *application =  [[UIApplication sharedApplication] delegate] ;
    dic[@"userid"] = [NSNumber numberWithInt: application.user.ID];
    dic[@"comments"] = self.textView.text;
    
    [manager GET:url parameters:dic success:^void(AFHTTPRequestOperation * operation, id  responseObject) {
        if ([responseObject[@"code"] intValue] == 0) {
            [[[UIAlertView alloc] initWithTitle:@"提示" message:@"评论成功！" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
            [self dismissViewControllerAnimated:YES completion:nil];
        }else
        {
            [[[UIAlertView alloc] initWithTitle:@"提示" message:@"很抱歉，！" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
        }
    } failure:^(AFHTTPRequestOperation *  operation, NSError * error) {
        NSLog(@"%@",error);
    }];
    
}

- (IBAction)back:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
